<extend name="Public:base" />
<block name="title"><title>心e购-购物车</title></block>
<block name="body">
	<header class="mui-bar mui-bar-nav">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<a class="mui-icon mui-icon-trash mui-pull-right" href="javascript:deleteCarts();"></a>
		<h1 class="mui-title">购物车</h1>
	</header>
	<div class="mui-content">
		<section>
			<ul class="gcw_list">
				<volist name="shop_cart_data" id="vo">
				<li class="list_box">
					<div class="gwc_list_header">
						<div class="mui-input-row mui-checkbox mui-left">
							<label>{$vo.store_name}</label>
							<input class="shop_check" type="checkbox">
						</div>
					</div>
					<volist name="vo.item" id="voc">
					<div class="gwc_list_content">
						<div class="mui-checkbox">
							<input class="good_check" value="{$voc.cart_id}" type="checkbox">
						</div>
						<div class="img_box">
							<img src="{$voc.goods_image}"/>
						</div>
						<div class="sp_xx">
							<div class=""><p class="sp_title mui-ellipsis">{$voc.goods_name}</p></div>
							<div><p>颜色：<span>{$voc.color_n}</span> 码数：<span>{$voc.spec_n}</span></p></div>
							<div>
								<span class="num">数量：</span>
								<div class="mui-numbox" data-numbox-min="1" data-numbox-max="99">
									<!--  data-numbox-max  为数量最大值，如果库存量就把库存量放进去-->
									<button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
									<input class="mui-input-numbox" type="number" value="{$voc.goods_num}">
									<button class="mui-btn mui-btn-numbox-plus" type="button" disabled="">+</button>
								</div>
							</div>
							<div><p class="sp_jg">
								<if condition="$voc.goods_price gt 0">
								价格：￥<span class="goods_price">{$voc['goods_price']}</span>
								</if>
								<if condition="$voc.point_num gt 0">
									<if condition="$voc.goods_price gt 0">+</if>
									积分：<span class="point_num">{$voc['point_num']}</span>
								</if>
								<if condition="$voc.coin_num gt 0">
									增值币：<span class="coin_num">{$voc['coin_num']}</span>
								</if>
							</p></div>
						</div>
					</div>
					</volist>
				</li>
				</volist>
			</ul>
		</section>
	</div>
	<div class="md_box dis_flex">
		<div class="dis_flex flex1">
			<div class="qx_box">
				<div class="mui-input-row mui-checkbox mui-left">
					<label>全选</label>
					<input onclick="allCheck(this)" type="checkbox">
				</div>
			</div>
			<div class="zj_box flex1">
				<div>合计：</div>
				<div class="zfjg show_all_price">
				</div>
			</div>
		</div>
		<div class="but_box">
			<a href="javascript:;">结&nbsp;算</a>
		</div>
	</div>
</block>
<block name="script">
	<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
	<!-- <script src="//cdn.bootcss.com/jquery/3.2.1/jquery.slim.min.js"></script> -->
	<script>
		$(".mui-btn-numbox-minus").click(function() {
			TotalPrice();
		});
		$(".mui-btn-numbox-plus").click(function() {
			TotalPrice();
		});
		$(".shop_check").click(function() {
			var _this = $(this);
			var checked = _this.prop("checked");
			_this.parents(".list_box").find(".good_check").prop('checked', checked);
			TotalPrice();
		});
		$(".good_check").click(function() {
			var _this = $(this);
			_this.parents(".list_box").find(".shop_check").prop('checked', true);
			TotalPrice();
		});
		function allCheck(e) {
			var checked = $(e).prop("checked");
			$(".good_check").prop('checked', checked);
			$(".shop_check").prop('checked', checked);
			TotalPrice();
		}
		function TotalPrice() {
			var goods_price_total = 0;
			var point_num_total = 0;
			var coin_num_total = 0;
			$(".list_box").each(function() {
				goods_price_total = 0;
				point_num_total = 0;
				coin_num_total = 0;
				$(this).find(".good_check").each(function() {
					var _this = $(this);
					var _thisps = _this.parents(".gwc_list_content");
					if(_this.is(":checked")) {
						var num = parseInt(_thisps.find(".mui-input-numbox").prop("value"));
						var goods_price = _thisps.find(".goods_price");
						if(goods_price.length > 0) {
							goods_price_total += parseFloat(goods_price.text()) * num;
						}
						var point_num = _thisps.find(".point_num");
						if(point_num.length > 0) {
							point_num_total += parseFloat(point_num.text()) * num;
						}
						var coin_num = _thisps.find(".coin_num");
						if(coin_num.length > 0) {
							coin_num_total += parseFloat(coin_num.text()) * num;
						}
					}
				});
			});
			var showPriceHtml = '';
			if(goods_price_total > 0) {
				showPriceHtml += '<p class="mui-ellipsis">价格：<span class="color_red">' + goods_price_total.toFixed(2) + '</span></p>';
			}
			if(point_num_total > 0) {
				showPriceHtml += '<p class="mui-ellipsis">积分：<span class="color_red">' + point_num_total.toFixed(2) + '</span></p>';
			}
			if(coin_num_total > 0) {
				showPriceHtml += '<p class="mui-ellipsis">增值币：<span class="color_red">' + coin_num_total.toFixed(2) + '</span></p>';
			}
			if (showPriceHtml === '') { 
				$('.show_all_price').html('<p class="mui-ellipsis">价格：<span class="color_red">0</span></p>');
			} else {
				$('.show_all_price').html(showPriceHtml);
			}
		}
		function deleteCarts() {
			var cart_ids = new Array;
			$(".good_check").each(function() {
				var _this = $(this);
				if(_this.is(":checked")) {
					cart_ids.push(parseInt(_this.prop("value")));
				}
			});
			if(cart_ids.length > 0) {
				$.post("/Wap/Shop/delete_cart", {"cart_ids": cart_ids}, function(data) {
					if(data.code === 0) {
						location.reload();
					} else if(data.code === 2) {
						location.href="/Wap/Member/login";
					} else {
						alert(data.message);
					}
				}, 'json');
			}
		}
	</script>
</block>